package com.ruoyi.common.mq.rabbit.service;

import com.ruoyi.common.mq.core.LogProducer;
import com.ruoyi.common.mq.rabbit.config.RabbitMQConfig;
import com.ruoyi.system.api.domain.SysOperLog;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LogProducerImpl implements LogProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendLog(SysOperLog operLog) {
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.LOG_EXCHANGE,
                RabbitMQConfig.LOG_ROUTING_KEY,
                operLog,
                message -> {
                    message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    return message;
                }
        );
    }
}